<template>
	<view>
		<view class="my-notice-bar">
			<view class="my-person-avatar" @click="changeUser">
				<up-avatar :src="src" size="66"></up-avatar>
			</view>
			<view class="my-notice-content" @click="changeUser">
				<view class="my-person-name">
					{{name}}
				</view>
				<view class="my-person-tip">
					查看并编辑个人资料
					<up-icon name="edit-pen" color="#c2c2c2" size="24"></up-icon>
				</view>
			</view>
			<view class="my-person-notice">
				<up-icon name="bell" color="#333" size="26"></up-icon>
			</view>
		</view>
		<view class="my-notice-bar my-notice-bar-bg">
			<up-icon name="volume" color="#ffffff" size="18"></up-icon>
			<view class="my-notice-content">
				今日水果半价免费配送
			</view>
			<view class="my-notice-right">
				查看<up-icon name="arrow-right" color="#676767" size="14"></up-icon>
			</view>
		</view>

		<view class="my-card">
			<view class="my-card-title">
				服务与设置
			</view>
			<up-grid :border="false" col="3" @click="click">
				<up-grid-item class="my-grid-item" v-for="(baseListItem,baseListIndex) in baseList"
					:key="baseListIndex">
					<view class="my-bg" :class="'my-bg-' + baseListItem.name">
						<up-icon :name="baseListItem.name" :size="28"></up-icon>
					</view>
					<text class="grid-text">{{baseListItem.title}}</text>
				</up-grid-item>
			</up-grid>
		</view>

		<up-modal :show="show" title="分享app下载二维码给好友" :close-on-click-overlay="true" @close="show=false">
			<template #default>
				<view class="slot-content">
					<up-image width="320rpx" height="320rpx"
						src="http://file.xjznpt.cn/tmp/download_code.png"></up-image>
				</view>
			</template>
			<template #confirmButton>
				<button type="primary" open-type="share">分享</button>
			</template>
		</up-modal>

	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import {
		onShareAppMessage,
		onShow
	} from '@dcloudio/uni-app'
	const idnName = "http://rke.xjznpt.cn/"
	const src = ref('')
	const name = ref("用户名");
	const show = ref(false)
	const baseList = ref([{
			name: 'home',
			title: '我的房屋',
			url: "/pages/mine/house/house"
		},
		{
			name: 'man-add',
			title: '我的家人',
			url: "/pages/mine/family/family"
		},
		{
			name: 'map',
			title: '收货地址',
			url: "/pages/mine/address/address"
		},
		{
			name: 'server-fill',
			title: '客服中心',
			url: "phone",
			mobile: "0351-7021966"
		},
		{
			name: 'file-text',
			title: '意见反馈',
			url: "/pages/mine/errlog/errlog"
		},
		{
			name: 'star', // 注意：这里修改了 name 从 'star' 改为 'volume'，以避免列表中两个元素具有相同的 name  
			title: '关于我们',
			url: "/pages/mine/about/about"
		},
		{
			name: 'question-circle', // 注意：这里修改了 name 从 'star' 改为 'volume'，以避免列表中两个元素具有相同的 name  
			title: '帮助中心',
			url: "/pages/mine/helper/helper"
		},
		{
			name: 'share-square', // 注意：这里修改了 name 从 'star' 改为 'volume'，以避免列表中两个元素具有相同的 name  
			title: '分享好友',
			url: "share",
		},
	]);

	const click = (name) => {
		console.log(name);
		const tmp = baseList.value[name];
		if (tmp.url === "phone") {
			uni.makePhoneCall({
				phoneNumber: tmp.mobile
			});
		} else if (tmp.url === "share") {
			show.value = true;
		} else {
			uni.navigateTo({
				url: tmp.url
			})
		}
	};

	onMounted(() => {
		const app = JSON.parse(uni.getStorageSync("app"));
		name.value = app.nickName;
		src.value = app.headImage ? idnName + app.headImage : ""
	});
	onShow(() => {
		console.log(222)
		const app = JSON.parse(uni.getStorageSync("app"));
		name.value = app.nickName;
		src.value = app.headImage ? idnName + app.headImage : ""
	})
	onShareAppMessage((res) => {
		if (res.from === 'button') { // 来自页面内分享按钮
			console.log(res.target)
		}
		return {
			title: '分享本页',
			path: '/pages/index/index'
		}
	});

	const onCancel = () => {
		show.value = false;
	}

	const changeUser = () => {
		uni.navigateTo({
			url: "/pages/mine/change/change"
		})
	}
</script>

<style lang="scss" scoped>
	.my-notice-bar {
		display: flex;
		align-items: center;
		padding: 40rpx 20rpx;
		border-radius: 10rpx;
		margin: 30rpx 30rpx 0;
		background-color: #fff;

		&.my-notice-bar-bg {
			padding: 20rpx 20rpx;
			margin-top: 60rpx;
			background-color: #e8a3a3;
		}

		.my-notice-right {
			display: flex;
			color: #676767;
			font-size: small;
			align-items: center;
		}

		.my-person-avatar {
			// padding: 0 20rpx;
		}
		.my-person-notice{
			margin-right: 20rpx;
		}
		.my-notice-content {
			flex: 1;
			margin-left: 20rpx;
			font-size: 28rpx;

			.my-person-name {
				font-size: 38rpx;
			}

			.my-person-tip {
				font-size: 26rpx;
				margin-top: 10rpx;
				color: #c2c2c2;
				display: flex;
			}
		}
	}

	.my-card {
		background-color: #fff;
		border-radius: 20rpx;
		padding: 20rpx 40rpx;
		margin: 60rpx 30rpx 0;

		.my-card-title {
			font-weight: bold;
			font-size: 28rpx;
			padding: 20rpx 0;
		}

		.my-grid-item {
			margin: 20rpx 0;

			.grid-text {
				font-size: 24rpx;
				color: #333;
				padding: 10rpx 0 20rpx 0rpx;
				box-sizing: border-box;
			}
		}
	}
</style>